<template>
	<view class="u-page">
		<view class="header">
		</view>
		<view class="content">
			<view class="projectList">
				<view style="margin: 40upx;">
					<ayQrcode ref="qrcode" :modal="modal_qr" :url="url" @hideQrcode="hideQrcode" :height="220" :width="220" />
				</view>
			</view>
			<view class="heyan" style="font-weight: 600;">你的权益二维码</view>
			<view class="heyan"><button type="warn" @click="baicun()">分享二维码</button></view>
			<view class="projectContent">
				<u-parse :content="data.power" ></u-parse>
			</view>
		</view>
		
		
	</view>
</template>

<script>
import ayQrcode from "@/components/ay-qrcode/ay-qrcode.vue"
import uParse from '@/components/u-parse/u-parse.vue'
	
    export default {
        components: {
            ayQrcode,
			uParse
        },
        data() {
            return {
				userData:{},
				pid:'',
				data:'',
                //二维码相关参数
                modal_qr: false,
                url: '', // 要生成的二维码值
            }
        },

        onLoad(e) {
			let user = uni.getStorageSync('userData');
			this.userData = user
			this.url = user.uid
			// console.log('1---',this.url)
			this.pid = e.id
            let that = this;
            that.showQrcode();//一加载生成二维码
			that.project();
        },
        methods: {
			async project(){
				const project = await this.GQL({
					"operationName": "allSlProjects",
					"query": "query allSlProjects($filter: SlProjectFilter) { allSlProjects(filter: $filter) { nodes { title projectInfo type tag status pic pid contentInfo cashier power} } }",
					"variables": {
						"filter": {
							"pid": {
								"equalTo": this.pid
							}
						}
					}
				})
				if (project.data.allSlProjects.node != '') {
					this.data = project.data.allSlProjects.nodes[0]
				}
			},
			
			
			
			baicun(){
				var that = this;
				//#ifdef MP-WEIXIN
				uni.showModal({
					title: '提示',
					content: '是否保存到相册',
					confirmText: '确定',
					confirmColor: '#33CCCC',
					success(res) {
						if (res.confirm) {
							that.saveImage();
						}
					}
				})
				// #endif
			},
			saveImage: function() {
				var that = this;
				uni.canvasToTempFilePath({
					canvasId: that.qrcode_id,
					success: function(res) {
						var tempFilePath = res.tempFilePath;
						console.log(tempFilePath);
						that.imagePath = tempFilePath;
						uni.saveImageToPhotosAlbum({
							filePath : tempFilePath ,
							success: function (res3) {
								uni.showModal({
									title: '提示',
									content: '保存成功',
									confirmText: '确定',
									showCancel: false,
									confirmColor: '#33CCCC',
									success(res4) {
										
									}
								}) 
							},
						});
					},
					fail: function(res) {
						console.log(res);
					}
				}, that);
			},
            // 展示二维码
            showQrcode() {
                let _this = this;
                this.modal_qr = true;
                // uni.showLoading()
                setTimeout(function() {
                    // uni.hideLoading()
                    _this.$refs.qrcode.crtQrCode()
                }, 50)
            },

            //传入组件的方法
            hideQrcode() {
                this.modal_qr = false;
            },
        }

    }
</script>

<style lang="scss">
.u-page{
		background-color: #FBFCFE;
	}
	 .header{
	 	width: 100%;
	 	height: 200px;
	 	/* color: #FFFFFF; */
	 	background: linear-gradient(#C7171E, #f0f2f5); /* 标准的语法 */
	 	
	 }
	.content{
		text-align: center;
		position: relative;
		top: -200px;
		background-color: #FFFFFF;
		border-radius: 5px;
		min-height: 500px;
		margin: 15px;
		.heyan{
			padding: 20px 0px;
			text-align: center;
			font-size: 16px;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #161E3E;
			line-height: 16px;
		}
		.projectList{
			margin-top: 20px;
			display: inline-block;
			align-items: center;
			text-align: center;
			width: 280px;
			height: 280px;
			background: #F2F3F6;
			border-radius: 5px;
			border: 1px solid #C1C8D9;
			
		}	
		button{
			box-shadow: 1px -2px 10px 6px rgba(0, 0, 0, 0.1);
		}
		.projectContent {
			text-align: left;
			margin-top: 20px;
		}
	}
	
</style>
